Add pre/post hooks and instance methods directly on the schema object returned by SchemaFactory.createForClass() before it is registered in the module. Pre-save hooks are the standard location for password hashing. Extend the document type with a TypeScript interface to get typed access to instance methods.
Apply hooks and methods to the schema object before registering it in MongooseModule.forFeature().
Use regular functions (not arrow functions) in hooks and methods — arrow functions do not bind this.
this.isModified('field') in pre-save hooks avoids rehashing an already-hashed password.
Extend the document interface to get TypeScript typing for instance methods.
Virtuals are not included in JSON output by default — set { toJSON: { virtuals: true } } on the schema.